"use strict";
var Player;
(function (Player) {
    Player["x"] = "x";
    Player["o"] = "o";
})(Player || (Player = {}));
let cells = document.querySelectorAll(".cell");
let bord = document.querySelector("#bord");
console.log(bord);
let win = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6],
];
let step = 0;
let currentPlayer;
currentPlayer = Player.x;
cells.forEach((item) => {
    let cell = item;
    cell.addEventListener("click", clickCell, { once: true });
});
function clickCell(e) {
    let target = e.target;
    target.classList.add(currentPlayer);
    step++;
    let isWin = checkWin(currentPlayer);
    if (isWin) {
        return alert('赢了');
    }
    if (step === 9) {
        return alert("平局");
    }
    // 提示信息
    bord.classList.remove('x', 'o');
    currentPlayer = currentPlayer == "x" ? Player.o : Player.x;
    bord.classList.add(currentPlayer);
}
function checkWin(player) {
    let isWin = win.some((item) => {
        // 先拿到 判赢数组中的每一个索引 然后 再去拿到 cells中的每一个元素 然后查看是否包含当前玩家
        let cell0 = cells[item[0]];
        let cell1 = cells[item[1]];
        let cell2 = cells[item[2]];
        if (cell0.classList.contains(player) &&
            cell1.classList.contains(player) &&
            cell2.classList.contains(player)) {
            return true;
        }
        return false;
    });
    return isWin;
}
